import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [{
      path: '/',
      redirect: {
        name: 'basic'
      }
    },
    {
      path: '/basic',
      name: 'basic',
      redirect: {
        name: 'home'
      },
      component: () =>
        import( /* webpackChunkName: "home" */ '../views/Basic/index.vue'),
      children: [{
          path: '/home',
          name: 'home',
          redirect: {
            name: 'hot'
          },
          component: () =>
            import( /* webpackChunkName: "home" */ '../views/Home/index.vue'),
          children: [{
              path: 'hot',
              name: 'hot',
              component: () => import('../views/Home/subpage/Hot.vue')
            },
            {
              /* /home/dress 与 dress表达的意思相同*/
              path: '/home/dress',
              name: 'dress',
              component: () => import('../views/Home/subpage/Dress.vue')
            },
            {
              path: 'shoeBag',
              name: 'shoeBag',
              component: () => import('../views/Home/subpage/ShoeBag.vue')
            }
          ]
        },
        {
          path: '/recomend',
          name: 'recomend',
          component: () =>
            import( /* webpackChunkName: "recomend" */ '../views/Recomend/index.vue')
        },
        {
          path: '/cart',
          name: 'cart',
          component: () =>
            import( /* webpackChunkName: "cart" */ '../views/Cart/index.vue')
        },
        {
          path: '/user',
          name: 'user',
          component: () =>
            import( /* webpackChunkName: "user" */ '../views/User/index.vue')
        }
      ]
    },
    {
      path: '/goodsDetail',
      name: 'goodsDetail',
      component: () => import('../views/GoodsDetail/index.vue')
    },
    {
      path: '/addressInfo',
      name: 'addressInfo',
      component: () => import('../views/User/addressInfo.vue')
    },
    {
      path: '/favorites',
      name: 'favorites',
      component: () => import('../views/User/favorites.vue')
    },
    {
      path: '/feedback',
      name: 'feedback',
      component: () => import('../views/User/feedback.vue')
    },
    {
      path: '/history',
      name: 'history',
      component: () => import('../views/User/history.vue')
    },
    {
      path: '/question',
      name: 'question',
      component: () => import('../views/User/question.vue')
    },
    {
      path: '/addAddress',
      name: 'addAddress',
      component: () => import('../views/User/addAddress.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/User/login.vue')
    },
    {
      path: '*',
      component: () => import('../views/NotFound/index.vue')
    }
  ],
  scrollBehavior(to, from, saveTop) {
    if (saveTop) {
      return saveTop;
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  }
});